#include<stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>


int main()
{
    pid_t id=fork();

    if(id == 0)
    {
        printf("i am child process\n");
        sleep(5);
    }
    else if(id > 0)
    {
        int status = -1;
        pid_t ret=waitpid(id,&status,0);
        if(ret == id)
        {
            pid_t _signal=status&0x7f;
            if(!_signal)
            {
                pid_t _coredump = (status>>7)&1;
                pid_t _exit = (status>>8)&0xff;
                printf("_cordump = %d\n",_coredump);
                if(!_exit)
                {
                    printf("_exit = %d\n",_exit);
                }
                else 
                {
                    printf("退出码有误：%d\n",_exit);
                }

            }
            else 
            {
                printf("子进程出异常，异常信号为 %d\n",_signal);
            }
        }
        else
        {
            printf("父进程等待失败\n");    
        }
    }


    return 0;
}


